
/*
* 写一个泛型类，求一个泛型数组中的最大值
* */

import javax.management.MBeanAttributeInfo;

class Alg<T extends Comparable<T>>{
    public T findMax(T [] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

//泛型方法：
class Alg2 {
    public<T extends Comparable<T>> T findMax(T [] array){
        T max = array[0];
        for (int i = 1; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0){
                max = array[i];
            }
        }
        return max;
    }
}

public class Test {
    public static void main(String[] args) {
        Integer [] array = {1,2,3,4,5,6,7};
        Alg<Integer> alg1 = new Alg<>();
        Integer max1 = alg1.findMax(array);
        System.out.println(max1);

        Alg2 alg2 = new Alg2();
        Integer max2 = alg2.<Integer>findMax(array);
        System.out.println(max2);
    }
}
